home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / amiga / chkabort.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  1KB  |  81 lines

  1.  
  2. /*
  3.  *  BREAK.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE, 
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  *  Internal routine to check for ^C
  10.  */
  11.  
  12. #define SysBase_DECLARED
  13.  
  14. #include <exec/types.h>
  15. #include <exec/tasks.h>
  16. #include <exec/execbase.h>
  17. #include <libraries/dos.h>
  18. #include <clib/exec_protos.h>
  19. #include <fcntl.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <signal.h>
  23.  
  24. typedef int (*fptr)(void);
  25.  
  26. static int brk(void);
  27.  
  28. /*
  29.  *  _SigIntFunc() is set by signal() if SIGINT is something other than the
  30.  *  default.  The reason for this is so the signal code is not included in
  31.  *  the executable unless explicitly called.
  32.  */
  33.  
  34. extern struct ExecBase *SysBase;
  35. extern __near short _AbortLockout;
  36. static int (*_BrkFunc)(void) = brk;
  37. void (*_SigIntFunc)(int);
  38.  
  39. void
  40. chkabort(void)
  41. {
  42.     struct Task *task = SysBase->ThisTask;
  43.  
  44.     if (_AbortLockout == 0) {
  45.     ++_AbortLockout;
  46.     if (task->tc_SigRecvd & SIGBREAKF_CTRL_C) {
  47.         SetSignal(0, SIGBREAKF_CTRL_C);
  48.         if ((*_BrkFunc)()) {
  49.         write(2, "^C\n", 3);
  50.         exit(EXIT_FAILURE);
  51.         }
  52.     }
  53.     --_AbortLockout;
  54.     }
  55. }
  56.  
  57. static int
  58. brk()
  59. {
  60.     if (_SigIntFunc) {
  61.     (*_SigIntFunc)(SIGINT);     /*    func might exit     */
  62.     return(0);            /*    do not exit        */
  63.     }
  64.     return(1);
  65. }
  66.  
  67. fptr
  68. onbreak(func)
  69. fptr func;
  70. {
  71.     fptr old = _BrkFunc;
  72.  
  73.     if (func == NULL) {
  74.     _BrkFunc = brk;
  75.     } else {
  76.     _BrkFunc = func;
  77.     }
  78.     return(old);
  79. }
  80.  
  81.